function login() {
	var url = "/wechat/user/login";
	if ($("#user-name").val() == "") {
		alert("用户名不能为空");
		return false;
	} else if ($("#user-psw").val() == "") {
		alert("密码不能为空");
		return false;
	} else {
		$.ajax({
			url : url,
			type : 'POST',
			dataType : 'json',
			contentType : 'text/html',
			data : JSON.stringify({
				userName : $("#user-name").val(),
				userPassword : $("#user-psw").val()
			}),
			success : function(data, status) {
				var status = status;
				if (status.toString() == "success") {
					alert("登录成功");
					top.window.location = "show.html";
				} else {
					alert("222");
					window.location.href = "views/userShow.jsp";
				}
			},
			error : function() {
				alert("用户名密码验证失败")
			}
		});
		return false;
	}
};


function register(){
	var imgSession = getSession()
	var url = "/wechat/user/register"
	var reUserName = $("#tel").val()
	var reUserPw = $("#psw").val()
	var reUserPwRepeat = $("#re-psw").val()
	var identifyingCode = $("#identifying-code").val()
	var number = $("#identifying-code").val();
	if (reUserName == "") {
        alert("用户名不能为空");
    }else if (reUserPw == "") {
        alert("密码不能为空");
    }else if (reUserPwRepeat == "") {
        alert("密码不能为空");
    }else if (reUserPw != reUserPwRepeat){
    	alert("两次密码不一致");
    }else if(number==""){
    	alert("请输入验证码");
    }else if(number!=imgSession){
    	alert("验证码错误，请重新输入");
    }else {
    	$.ajax({
    		url: url,
    		async: true,
            type: 'POST',
            dataType : 'json',
            contentType : 'text/html',
            data:JSON.stringify({
            	userName: reUserName,
            	userPassword: reUserPw
            }),
            success: function (data, status) {
                var status = status;
                if (status.toString() == "success") {
                	alert('注册成功，请登录');
                	top.window.location ="login.html";
                }
                else{
                	window.location.href="";
                }
            },
            error: function () { alert("用户名密码验证失败") }
    	});
    }
};

function getSession(){
	var imgSession =""
	var url = "/wechat/user/getsession";
	$.ajax({
		async: false,
		url: url,
        type: 'GET',
        dataType : 'json',
        success: function (data, status) {
            var status = status
            if (status.toString() == "success") {
            	imgSession=data
            }
        },
        error: function () { alert("获取session失败") }
	});
	return imgSession;
}
